package com.example.demo.controller;

import com.example.demo.pojo.Preservation;
import com.example.demo.pojo.request.PreservationRequest;
import com.example.demo.service.PreservationService;
import com.example.demo.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 程序员小洋
 * @version 2022.3
 * @date 2023/5/9 09:20
 * @title 项目维修控制器
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/preservation")
@CrossOrigin
@Api(tags = "项目维修控制器")
public class PreservationController {

    @Autowired
    private PreservationService preservationService;

    /**
     * 新增
     * @param preservation
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增")
    public Result save(@RequestBody Preservation preservation) {
        preservationService.save(preservation);
        return Result.success();
    }

    /**
     * 修改
     * @param preservation
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改")
    public Result update(@RequestBody Preservation preservation) {
        preservationService.update(preservation);
        return Result.success();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除")
    public Result delete(@PathVariable Integer id) {
        preservationService.deleteById(id);
        return Result.success();
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public Result getById(@PathVariable Integer id) {
        Preservation preservation = preservationService.getById(id);
        return Result.success(preservation);
    }

    /**
     * 条件查询
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("条件查询")
    public Result list(PreservationRequest preservationRequest) {
        List<Preservation> list = preservationService.list(preservationRequest);
        return Result.success(list);
    }

}
